package com.cnxjs.shs4et.config;

import com.cnxjs.shs4et.interceptors.LoginInterceptor;
import com.cnxjs.shs4et.interceptors.RoleBasedAuthorizationInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class Webconfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;
    @Autowired
    private RoleBasedAuthorizationInterceptor roleBasedAuthorizationInterceptor;

    public void addInterceptors(InterceptorRegistry registry){
        // 注册和登录不拦截
        registry.addInterceptor(loginInterceptor).excludePathPatterns("/user/register","/user/login");
        // 角色权限拦截器
        registry.addInterceptor(roleBasedAuthorizationInterceptor)
                .addPathPatterns("/**"); // 应用于所有路径
    }
}
